//
//  IntegralMallClearingVC.m
//  lmq
//
//  Created by 马田成 on 2017/4/3.
//  Copyright © 2017年 yuanxin. All rights reserved.
//

#import "IntegralMallClearingVC.h"
#import "UIImageView+WebCache.h"
#import "MyAndSnatchViewController.h"
#import "addressViewController.h"


@interface IntegralMallClearingVC ()
@property (weak, nonatomic) IBOutlet UIImageView *pic;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *jiFenLabel;
@property (weak, nonatomic) IBOutlet UILabel *consigneeLbel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;//地址
@property (weak, nonatomic) IBOutlet UILabel *allMoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *currentJF;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel2;


@end

@implementation IntegralMallClearingVC
- (void)viewWillAppear:(BOOL)animated{

    [self creationDate];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationDate];
    
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)addressButton:(UIButton *)sender {
    
    
    addressViewController *vc = [[addressViewController alloc] init];
    
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)creationDate{
    

    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    [productParams setValue:self.shop_id forKey:@"shop_id"];
    NSString *tokenStr=[PublicFunction getConfigWithKey:@"token"];
    NSString *memberId = [PublicFunction getConfigWithKey:@"uid"];
    [productParams setValue:tokenStr forKey:@"token"];
    [productParams setValue:memberId forKey:@"member_id"];
    [productParams setValue:self.num forKey:@"num"];
    [[MNetworkHandler sharedInstance]conURL:Home_OnebuyToAccount
                                networkType:NetWorkPOST
                                     params:productParams
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   if ([[returnData objectForKey:@"code"]intValue]==1) {
                                       NSMutableDictionary *dictShop = [returnData objectForKey:@"shop"];
                                       
    self.name.text = [dictShop objectForKey:@"name"];
    NSString *strOfBuy = @"购买次数:";
    self.priceLabel.text =[strOfBuy stringByAppendingString:self.num];

//    NSString *strPic = @"http://lmq.quyum.cn/";
//                                       
//    NSString *str = [strPic stringByAppendingString:[dictShop objectForKey:@"pic"]];
                                      
    NSString *urlWare=[dictShop objectForKey:@"pic"];
    NSString *urlN=manage(AP_HOST, urlWare);
                                       
                                       
    NSString *strUrl = [urlN stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
                                       
    [self.pic sd_setImageWithURL:[NSURL URLWithString:strUrl]];
                                       
    NSMutableDictionary *dicOfAddress = [returnData objectForKey:@"address"];
    self.phoneLabel.text = [dicOfAddress objectForKey:@"phone"];
                                       
    NSInteger money1 = [[returnData objectForKey:@"money"] intValue];
                                       
    self.jiFenLabel.text = [NSString stringWithFormat:@"%ld", (long)money1];
    NSString *strOfJF = @"当前积分:";
    self.currentJF.text =[strOfJF stringByAppendingString: [returnData objectForKey:@"user_integral"]];
    NSString *strAll = @"总计:";
    NSString *strall1 = [NSString stringWithFormat:@"%ld", (long)money1];

    self.allMoneyLabel.text = [strAll stringByAppendingString:strall1];
                                       
                                       
    NSString *strconsignee = @"收件人:";
    self.consigneeLbel.text =[strconsignee stringByAppendingString:[dicOfAddress objectForKey:@"consignee"]];
    NSString *strPhone2 = @"手机号:";
    self.phoneLabel2.text = [strPhone2 stringByAppendingString:[dicOfAddress objectForKey:@"phone"]];
                                       
    NSString *strAddress = @"收货地址:";
    self.addressLabel.text = [[strAddress stringByAppendingString:[dicOfAddress objectForKey:@"region"]] stringByAppendingString:[dicOfAddress objectForKey:@"information"]];
                                       
    self.addressID = [[dicOfAddress objectForKey:@"id"] intValue];
                                       
                                       
                                       
                                       NSLog(@"%@", returnData);
                                       
                                   }
                                   else{
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                   }
                               } failureBlock:^(NSError *error) {
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
                               }];
    
}
- (IBAction)payment:(UIButton *)sender {
    
    NSString *strID = [NSString stringWithFormat:@"%ld", (long)self.addressID];
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    [productParams setValue:self.shop_id forKey:@"shop_id"];
    NSString *tokenStr=[PublicFunction getConfigWithKey:@"token"];
    NSString *memberId = [PublicFunction getConfigWithKey:@"uid"];
    [productParams setValue:tokenStr forKey:@"token"];
    [productParams setValue:memberId forKey:@"member_id"];
    [productParams setValue:self.num forKey:@"num"];
    [productParams setValue:strID forKey:@"address_id"];
    
    [[MNetworkHandler sharedInstance]conURL:Home_OnebuyTobuy
                                networkType:NetWorkPOST
                                     params:productParams
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   if ([[returnData objectForKey:@"code"]intValue]==1) {
                                       
                                       MyAndSnatchViewController *vc = [[MyAndSnatchViewController alloc] init];
                                       [self.navigationController pushViewController:vc animated:YES];
                                       
                                       
                                       
                                       
                                       
                                   }
                                   else{
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                   }
                               } failureBlock:^(NSError *error) {
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
                               }];

    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
